package cloud.seri.auth.domain

import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.mapping.Document
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size
import java.io.Serializable
import java.util.Objects

/**
 * An authority (a security role) used by Spring Security.
 */
@Document(collection = "seri_authority")
data class Authority(

    @Id
    var id: String? = null,

    @field:NotNull
    @field:Size(max = 50)
    var name: String? = null,

    var aliasName: String? = null,

    var sort: Int? = null

) : Serializable
{

    override fun equals(other: Any?): Boolean
    {
        if (this === other) return true
        if (other !is Authority) return false
        if (other.name == null || name == null) return false

        return Objects.equals(name, other.name)
    }

    override fun hashCode(): Int
    {
        return 31
    }

    companion object
    {
        private const val serialVersionUID = 1L
    }
}
